/* 快速幂
    int qmi(int base, int index, int MOD)
    {
        int res = 1;
        while(index){
            //printf("res:%d base:%d index:%d\n", res, base, index);
            if(index & 1) res = (res * base) % MOD;
            base = (base * base)%MOD;
            index >>= 1;
        }
        return res;
    }

* 本题:
    等差 a[k] = a[1] + d*(k-1)
    等比 a[k] = a[1] * q^(k-1)
*/

#define DEBUG
#pragma GCC optimize("O1,O2,O3,Ofast")
#pragma GCC optimize("no-stack-protector,unroll-loops,fast-math,inline")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,sse4,sse4.1,sse4.2,ssse3")


#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

// #define int long long

const int N = 1e6+10, MOD = 200907;
int primes[N], cnt;
bool st[N];

int qmi(int base, int index, int MOD)
{
    int res = 1;
    while(index){
        //printf("res:%d base:%d index:%d\n", res, base, index);
        if(index & 1) res = (res * base) % MOD;
        base = (base * base)%MOD;
        index >>= 1;
    }
    return res;
}

signed main()
{
    #ifdef DEBUG
        freopen("./in.txt", "r", stdin);
    #else
        ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #endif

    int T; cin >> T;
    while(T--)
    {
        int a, b, c, k; cin >> a >> b >> c >> k;
        if(b-a == c-b){ //等差
            int d = b - a;
            printf("%d\n", (a + d*(k-1))%MOD);
        }
        else {
            int q = b/a;
            printf("%d\n", (a * qmi(q, k-1, MOD))%MOD);
        }
    }
    return 0;
}
